package com.bodacn.keypoint.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bodacn.keypoint.R;
import com.bodacn.keypoint.bean.TaskTopBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by KangJunjie on 2020/6/18.
 */
public class TaskTopAdapter extends BaseAdapter {
    private Context context;
    private List<TaskTopBean> dataBeans;

    public TaskTopAdapter(Context context, List<TaskTopBean> beanList) {
        this.context = context;
        this.dataBeans = beanList;
    }

    @Override
    public int getCount() {
        return dataBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return dataBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_task_top_head, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (dataBeans.size() > 0) {
            TaskTopBean taskTopBean = dataBeans.get(position);
            if (!TextUtils.isEmpty(taskTopBean.getSize())){
                viewHolder.tvCm.setText(taskTopBean.getSize());
            }else {
                viewHolder.tvCm.setText("");
            }
            if (!TextUtils.isEmpty(taskTopBean.getColor())){
                viewHolder.tvColor.setText(taskTopBean.getColor());
            }else {
                viewHolder.tvColor.setText("");
            }
            if (!TextUtils.isEmpty(taskTopBean.getOrderNum())){
                viewHolder.tvDds.setText(taskTopBean.getOrderNum());
            }else {
                viewHolder.tvDds.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getTodayNum())){
                viewHolder.tvDrpcs.setText(taskTopBean.getTodayNum());
            }else {
                viewHolder.tvDrpcs.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getWorker())){
                viewHolder.tvFzr.setText(taskTopBean.getWorker());
            }else {
                viewHolder.tvFzr.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getLastNum())){
                viewHolder.tvJy.setText(taskTopBean.getLastNum());
            }else {
                viewHolder.tvJy.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getStyleNo())){
                viewHolder.tvKh.setText(taskTopBean.getStyleNo());
            }else {
                viewHolder.tvKh.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getDayNum())){
                viewHolder.tvPcts.setText(taskTopBean.getDayNum());
            }else {
                viewHolder.tvPcts.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getPDDate())){
                viewHolder.tvPdrq.setText(taskTopBean.getPDDate());
            }else {
                viewHolder.tvPdrq.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getLineDate())){
                viewHolder.tvSxrq.setText(taskTopBean.getLineDate());
            }else {
                viewHolder.tvSxrq.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getCode())){
                viewHolder.tvZdh.setText(taskTopBean.getCode());
            }else {
                viewHolder.tvZdh.setText("");
            }
        }
        return convertView;
    }

    public interface OrderDetialOn {
        void Onclick(int position);
    }



    class ViewHolder {
        @BindView(R.id.tv_pdrq)
        TextView tvPdrq;
        @BindView(R.id.tv_zdh)
        TextView tvZdh;
        @BindView(R.id.tv_kh)
        TextView tvKh;
        @BindView(R.id.tv_color)
        TextView tvColor;
        @BindView(R.id.tv_cm)
        TextView tvCm;
        @BindView(R.id.tv_dds)
        TextView tvDds;
        @BindView(R.id.tv_drpcs)
        TextView tvDrpcs;
        @BindView(R.id.tv_jy)
        TextView tvJy;
        @BindView(R.id.tv_pcts)
        TextView tvPcts;
        @BindView(R.id.tv_fzr)
        TextView tvFzr;
        @BindView(R.id.tv_sxrq)
        TextView tvSxrq;
        @BindView(R.id.ll)
        LinearLayout ll;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
